package io;

import javax.swing.text.Style;
import java.io.*;

/**
 * 缓冲流:是一对高级流，作用是加快读写效率
 * 1)BufferedInputStream:缓冲输入流
 * 2)BufferedOutputStream:缓冲输出流
 * 缓冲流读写效率快的原因:
 *
 */
public class CopyDemo3Buffered {
    public static void main(String[] args) throws IOException {
        FileInputStream fis = new FileInputStream("xy.jpg");
        BufferedInputStream bis = new BufferedInputStream(fis);
        FileOutputStream fos = new FileOutputStream("bs_cp.jpg");
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        long start = System.currentTimeMillis();
        int d;
        while((d=bis.read())!=-1){//使用缓冲流读取字节
            bos.write(d);//使用缓冲流写出字节
        }
        long end = System.currentTimeMillis();
        System.out.println("复制完成，耗时:"+(end-start)+"ms");

        bos.close();//只需关高级流，因为高级流中先关了低级流
        bis.close();
    }
}
